\chapter{Problem Domain}
\label{chapter:ProblemDomain}
Components covers the different game entities and organization thereof. Flow covers the progression of a game, what actions are allowed and in which order. Rules cover what actions are affected by rules and in what way. 
\section{Components and Ownership}
\label{section:ProblemDomain}

Figure \ref{fig:rp_components} illustrates the abstract composition of a board game. 

			\begin{figure}[h!t]
				\begin{center}
					\includegraphics[width=\textwidth]{Analysis/RP1-structure.pdf}
				\end{center}
				\caption{Rich Picture: Components}
				\label{fig:rp_components}
			\end{figure}
			
Board games revolve around players, who have access to pieces, hands and actions. Pieces are placed in boards, which are organized in boards. Cards are held in hands and drawn from decks. When played they invoke actions and subsequently effects. Players have access to actions as well, which also lets them cause effects in the game. Effects, depending on action, can have a wide range of influences on the game, causing changes to pieces, cards, boards or score, if the game contains a score system.

\subsection{Structures}
			
Hands, decks and boards are structures for containing other elements; boards contain fields and subsequently pieces, while decks and hands contain cards. 


\subsubsection{Boards}

Boards are areas in which players can place and move cards or pieces. Their dimensions can vary; 8x8 for chess, 1x60 for single path games such as Ludo.

Boards consist of fields, some of which may be special. Each field is connected to other fields, which lie adjacently. Some cells have special rules that activate when a piece enters the cell, or when a piece passes through it. In Ludo special cells include globes, stars and the entry points to the goal (see section \ref{section:Ludo} on Ludo for details).

%In some games, cards are also placed in boards, although they never function as pieces.


\subsubsection{Hands}

Hands are similar to boards, except they do not have rules of movement; a player can position his cards however he pleases, and contain cards rather than pieces. A hand also belongs to a player, while boards are accessible to everyone, with exceptions to subareas that have special rules for entry. For example, only red pieces can enter the red goal area in Ludo.


\subsubsection{Deck}

A deck is a sequence of cards, usually used to draw a card from. They are normally randomized to prevent predictability in outcome. It is unusual for players to pick cards that are not the top card.

\subsection{Entity classes}

An entity is a physical object present within the game, such as a piece or a card, that is manipulated by a player during the course of a game.

\subsubsection{Piece}

Represents a piece in the board game. Every piece has an owner, either one of the players or a neutral owner, and occupies one field.
Pieces can be placed, moved, removed and sometimes activated. When a piece enters a field that is already occupied by another piece, a collision occurs. Rules for collisions depend on the particular board game; sometimes the piece occupying the field is removed, sometimes special benefits are given to the entering player, or the pieces may simply share the field.

\subsubsection{Card}

Represents a card, which cause varying effects. Cards are sometimes used as points, invoke special rules, or grant actions when played. For example, it may require a player to discard one piece, or when activated it may simply compare its value to another cards'. Cards are drawn, then usually placed in the hand belonging to the player who drew it.

\subsubsection{Dice}

Board games deploy many varieties of randomization to avoid predictability, however as they are all functionally identical this report covers all variations under the term dice. When rolled, they produce a random result in their range. Some dice produce numerical results, while others determine a specific action to be taken.

\subsection{Player}

The players perform all the actions as specified by the game's round setup. If cards are present, the player has a hand in which all cards available to him are held. Some games allow players to take special actions during turns.

\subsection{Information}

Information elements are used to keep track of data in the game. They may be pieces (tokens), cards or a notepad depending on the actual game, but they all function to keep track of values and acquisitions as the game progresses. 

\section{Actions and effects}
\label{sec:actions_and_effects}

Actions such as moving/placing a piece, playing a card or special game specific actions, are initiated by players. The standard actions are as follows:

\begin{itemize}
	\item Place / Move / Remove / Activate (Piece)
	\item Draw / Move / Discard / Play (Card\footnote{Note the structural similarity between pieces and cards})
	\item End Turn
	\item Surrender
\end{itemize}

Some games define special actions, such as exchanging one piece with another, like kings in checkers (See section \ref{section:Checkers}). These special actions are defined by their effect.

An effect is the difference in the game before and after an action occurs. The \textit{place} action has the effect of a new piece being introduced to the game, the \textit{move} action changes the position of a piece, the \textit{discard} action removes a card from the player's hand, etc.


\section{Flow}
\label{sec:flow}

When the game begins, a round is initiated. Rounds dictate the order of turns and subsequently what actions can be performed when.

			\begin{figure}[h!t]
				\begin{center}
				\includegraphics[width=0.6\textwidth]{Analysis/RP2-flow.pdf}
				\end{center}
				\caption{Rich Picture: Flow of Rounds}
				\label{fig:rp_flow_rounds}
			\end{figure}

Turns determine the actions a player can take, e.g. draw a card, play a card, move a piece.
			
As the number of times an entity class will engage an action, if at all, is entirely determined by each game individually, which is why the event table in table \ref{tbl:event_table} instead contains the events that are always related to a class (Provided the class is used in the board game) and the classes that may use it.
%Read the table as:
%\begin{itemize}
%	\item{* means class is always involved}
%	\item{+ means class may be involved depending on the specific game}
%\end{itemize}


%\label{tbl:event_table}
%		\begin{tabular}{|l|*6{c|}}
%		\hline
%		\textbf{Event} / \textbf{Class}	& Piece	& Dice	& Card & Grid	& Turn	& Player \\ \hline
%		Initial Setup 	& *	& 	& +	& * & 	& * \\ \hline
%		Game Starts 	&  	&  	& +	&   & *	&   \\ \hline
%		Card Drawn		&  	& 	& *	& * & 	&   \\ \hline
%		Card Played 	& +	& +	& *	& + & + & * \\ \hline
%		Card Discarded  &  	&  	& *	&   &   &   \\ \hline
%		Piece Placed 	& *	&  	& 	& * & 	&   \\ \hline
%		Piece Removed 	& *	&  	& 	&   & 	&   \\ \hline
%		Pierce Collision	& *	& +	& 	&   & 	&   \\ \hline
%		Piece Moved 	& *	& +	& 	& * & 	&   \\ \hline
%		Piece Activated & *	& +	& +	& + & 	& + \\ \hline
%		Enter Field		& *	&  	&  	& * & 	& + \\ \hline
%		Action Taken 	& +	& +	& +	& + & *	& * \\ \hline
%		Turn Ends 		& 	& 	& 	&   & * & * \\ \hline
%		Game Ends 		& 	& 	& 	&   & *	& * \\ \hline
%		\end{tabular}	
		
\subsection{Event Descriptions}

The following gives detailed descriptions of the events and their occurrence.

\subsubsection{Static Events}

Static events occur at set points during the games flow. They always occur regardless of player actions as they are dependent on the game's flow, not on the player's moves.

\paragraph{Initial Setup}

Occurs before game start. Pieces are placed in starting positions, and information elements are set to starting values.

\paragraph{Game Starts}

After the initial setup the flow is initiated (See rich picture \ref{fig:rp_flow_rounds}) by activating a round. Some games determine the order of player turns in this face. 

\paragraph{Turn Ends}
After a player declares the end of his turn, or has no available actions, his turn ends. The next turn begins according to the game's round system.

\paragraph{Round Ends}

If a game has static occurrences they are often engaged at the end of a round. 

\paragraph{Game Ends}

Some games end when a player satisfies his victory condition, when a player satisfies a lose condition, or when all players satisfy either condition. Winners and losers are declared and possibly ranked, then the game is over.

\subsubsection{Dynamic Events}

Dynamic events occur sporadically over the course of a game, as they are caused by player actions, such as moving a piece or playing a card. While some games force these actions, they may become static in certain games, but it is not guaranteed, which marks their difference from static events, which always occur regardless of game.

\texttt{Place / Move / Remove / Activate (Piece), Draw / Move / Discard / Play (Card)}

Occurs when the corresponding action is taken 

\paragraph{Enter Field}

Occurs every time a piece is placed on a field. A piece can also cause this event when passing through a field without stopping. (In checkers passing through a field with an occupying piece removes it.)

\paragraph{Collision}

Collision occurs when two pieces occupy the same field. In Ludo this results in the \textit{defender} being removed, while the \textit{attacker} occupies the field in its place. As events are instant, two pieces do not cause collision if they are occupying the same field over a period of time, collision occurs the moment a piece enters a field already occupied. 

\section{Actions and Rules}

This section expands the relationship between actions and effects, and introduces the concept of rules.

Rules are restrictions on actions, limiting their outcomes or denying them entirely; for example a piece may only be allowed to move a set distance, defined by a rule, and moves to fields outside that distance are illegal. As shown in figure \ref{fig:rp_rules} when an action is chosen it must pass through the rules of the game. For example, a player may not be allowed to draw a card (action) while he has seven cards or more in his hand (rule). Every action is either legal or illegal based on whether or not it violates a rule.

An action has no effect if it does not comply with the game's rules (See figure \ref{fig:rp_compliance} including not spending the player's action, leaving them free to chose another. Rules are defined for every action, but may depend on outside factors.

Rules can also be applied to events, the win and lose conditions are examples of this.


			\begin{figure}[h!t]
				\begin{center}
				\includegraphics[width=\textwidth]{Analysis/RP3-rules.pdf}
				\end{center}
				\caption{Rich Picture: Actions - Rules - Effects relation}
				\label{fig:rp_rules}
			\end{figure}
			
			\begin{figure}[h!t]
				\begin{center}
				\includegraphics[width=\textwidth]{Analysis/RP4-compliance.pdf}
				\end{center}
				\caption{Rich Picture: Compliance to rules}
				\label{fig:rp_compliance}
			\end{figure}
